package cmsc128.proj.iterc.dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;


/**
 * This class was autogenerated by Torque on:
 *
 * [Tue Feb 23 23:07:31 GMT 2010]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Student
 */
public abstract class BaseStudent extends BaseObject
{
    /** The Peer class */
    private static final StudentPeer peer =
        new StudentPeer();

        
    /** The value for the student_number field */
    private int student_number;
      
    /** The value for the college field */
    private String college;
      
    /** The value for the course field */
    private String course;
      
    /** The value for the firstname field */
    private String firstname;
      
    /** The value for the middleinitial field */
    private String middleinitial;
      
    /** The value for the lastname field */
    private String lastname;
      
    /** The value for the contact field */
    private String contact;
      
    /** The value for the address field */
    private String address;
      
    /** The value for the birthday field */
    private Date birthday;
  
    
    /**
     * Get the Student_number
     *
     * @return int
     */
    public int getStudent_number()
    {
        return student_number;
    }

                        
    /**
     * Set the value of Student_number
     *
     * @param v new value
     */
    public void setStudent_number(int v) 
    {
    
                  if (this.student_number != v)
              {
            this.student_number = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the College
     *
     * @return String
     */
    public String getCollege()
    {
        return college;
    }

                        
    /**
     * Set the value of College
     *
     * @param v new value
     */
    public void setCollege(String v) 
    {
    
                  if (!ObjectUtils.equals(this.college, v))
              {
            this.college = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Course
     *
     * @return String
     */
    public String getCourse()
    {
        return course;
    }

                        
    /**
     * Set the value of Course
     *
     * @param v new value
     */
    public void setCourse(String v) 
    {
    
                  if (!ObjectUtils.equals(this.course, v))
              {
            this.course = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Firstname
     *
     * @return String
     */
    public String getFirstname()
    {
        return firstname;
    }

                        
    /**
     * Set the value of Firstname
     *
     * @param v new value
     */
    public void setFirstname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.firstname, v))
              {
            this.firstname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Middleinitial
     *
     * @return String
     */
    public String getMiddleinitial()
    {
        return middleinitial;
    }

                        
    /**
     * Set the value of Middleinitial
     *
     * @param v new value
     */
    public void setMiddleinitial(String v) 
    {
    
                  if (!ObjectUtils.equals(this.middleinitial, v))
              {
            this.middleinitial = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Lastname
     *
     * @return String
     */
    public String getLastname()
    {
        return lastname;
    }

                        
    /**
     * Set the value of Lastname
     *
     * @param v new value
     */
    public void setLastname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.lastname, v))
              {
            this.lastname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Contact
     *
     * @return String
     */
    public String getContact()
    {
        return contact;
    }

                        
    /**
     * Set the value of Contact
     *
     * @param v new value
     */
    public void setContact(String v) 
    {
    
                  if (!ObjectUtils.equals(this.contact, v))
              {
            this.contact = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Address
     *
     * @return String
     */
    public String getAddress()
    {
        return address;
    }

                        
    /**
     * Set the value of Address
     *
     * @param v new value
     */
    public void setAddress(String v) 
    {
    
                  if (!ObjectUtils.equals(this.address, v))
              {
            this.address = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Birthday
     *
     * @return Date
     */
    public Date getBirthday()
    {
        return birthday;
    }

                        
    /**
     * Set the value of Birthday
     *
     * @param v new value
     */
    public void setBirthday(Date v) 
    {
    
                  if (!ObjectUtils.equals(this.birthday, v))
              {
            this.birthday = v;
            setModified(true);
        }
    
          
              }
  
         
                
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Student_number");
              fieldNames.add("College");
              fieldNames.add("Course");
              fieldNames.add("Firstname");
              fieldNames.add("Middleinitial");
              fieldNames.add("Lastname");
              fieldNames.add("Contact");
              fieldNames.add("Address");
              fieldNames.add("Birthday");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Student_number"))
        {
                return new Integer(getStudent_number());
            }
          if (name.equals("College"))
        {
                return getCollege();
            }
          if (name.equals("Course"))
        {
                return getCourse();
            }
          if (name.equals("Firstname"))
        {
                return getFirstname();
            }
          if (name.equals("Middleinitial"))
        {
                return getMiddleinitial();
            }
          if (name.equals("Lastname"))
        {
                return getLastname();
            }
          if (name.equals("Contact"))
        {
                return getContact();
            }
          if (name.equals("Address"))
        {
                return getAddress();
            }
          if (name.equals("Birthday"))
        {
                return getBirthday();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(StudentPeer.STUDENT_NUMBER))
        {
                return new Integer(getStudent_number());
            }
          if (name.equals(StudentPeer.COLLEGE))
        {
                return getCollege();
            }
          if (name.equals(StudentPeer.COURSE))
        {
                return getCourse();
            }
          if (name.equals(StudentPeer.FIRSTNAME))
        {
                return getFirstname();
            }
          if (name.equals(StudentPeer.MIDDLEINITIAL))
        {
                return getMiddleinitial();
            }
          if (name.equals(StudentPeer.LASTNAME))
        {
                return getLastname();
            }
          if (name.equals(StudentPeer.CONTACT))
        {
                return getContact();
            }
          if (name.equals(StudentPeer.ADDRESS))
        {
                return getAddress();
            }
          if (name.equals(StudentPeer.BIRTHDAY))
        {
                return getBirthday();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getStudent_number());
            }
              if (pos == 1)
        {
                return getCollege();
            }
              if (pos == 2)
        {
                return getCourse();
            }
              if (pos == 3)
        {
                return getFirstname();
            }
              if (pos == 4)
        {
                return getMiddleinitial();
            }
              if (pos == 5)
        {
                return getLastname();
            }
              if (pos == 6)
        {
                return getContact();
            }
              if (pos == 7)
        {
                return getAddress();
            }
              if (pos == 8)
        {
                return getBirthday();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(StudentPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    StudentPeer.doInsert((Student) this, con);
                    setNew(false);
                }
                else
                {
                    StudentPeer.doUpdate((Student) this, con);
                }
            }

                      alreadyInSave = false;
        }
      }


                    
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  student_number ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
            setStudent_number(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
            setStudent_number(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getStudent_number());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public Student copy() throws TorqueException
    {
        return copyInto(new Student());
    }
  
    protected Student copyInto(Student copyObj) throws TorqueException
    {
          copyObj.setStudent_number(student_number);
          copyObj.setCollege(college);
          copyObj.setCourse(course);
          copyObj.setFirstname(firstname);
          copyObj.setMiddleinitial(middleinitial);
          copyObj.setLastname(lastname);
          copyObj.setContact(contact);
          copyObj.setAddress(address);
          copyObj.setBirthday(birthday);
  
                    copyObj.setStudent_number(0);
                                                            
        
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public StudentPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Student:\n");
        str.append("Student_number = ")
           .append(getStudent_number())
           .append("\n");
        str.append("College = ")
           .append(getCollege())
           .append("\n");
        str.append("Course = ")
           .append(getCourse())
           .append("\n");
        str.append("Firstname = ")
           .append(getFirstname())
           .append("\n");
        str.append("Middleinitial = ")
           .append(getMiddleinitial())
           .append("\n");
        str.append("Lastname = ")
           .append(getLastname())
           .append("\n");
        str.append("Contact = ")
           .append(getContact())
           .append("\n");
        str.append("Address = ")
           .append(getAddress())
           .append("\n");
        str.append("Birthday = ")
           .append(getBirthday())
           .append("\n");
        return(str.toString());
    }
}
